﻿using System.ComponentModel;
using System;

namespace BotModels
{
    public abstract class ModelBase : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        protected void RaisePropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        public T Clone<T>()
        {
            Type t = this.GetType();
            T clone = (T)Activator.CreateInstance(t);
            var props = t.GetProperties();

            foreach (var prop in props)
            {
                if (prop.CanWrite)
                {
                    var thisValue = prop.GetValue(this, null);
                    prop.SetValue(clone, thisValue, null);
                }
            }

            return clone;
        }
    }
}
